import React from 'react';
import { KfBizDataSelect, KfBizDataSelectProps, KfBizDataTableSelect, KfBizDataTableSelectProps } from 'kf-web-library';
import * as API from '@/services';
import classNames from 'classnames';
import {BizKfExtraProColumnType} from "@/components";

const HxJournalPeriodSelect = (props: Partial<KfBizDataSelectProps<API.JournalPeriod, API.JournalPeriodPageQueryParams>>) => {
  return (
    <KfBizDataSelect<API.JournalPeriod, API.JournalPeriodPageQueryParams>
      request={(p) => API.queryJournalPeriods({
        ...p ,
        pageSize: 1000,
      })}
      entityKeys={{
        primaryKey: 'id',
        labelKey: 'periodName',
      }}
      {...props}
      className={classNames("hx-journal-period-select", props?.className)}
    />
  );
};

const HxJournalPeriodTableSelect = (
  props: Partial<KfBizDataTableSelectProps<API.JournalPeriod, API.JournalPeriodPageQueryParams, BizKfExtraProColumnType>>,
) => {
  return (
    <KfBizDataTableSelect<API.JournalPeriod, API.JournalPeriodPageQueryParams, BizKfExtraProColumnType>
      entityTypeName={"刊期"}
      columns={[
        {
          title: '刊期',
          dataIndex: "periodName",
          sorter: false,
          hideInSearch: true,
          ellipsis: true,
        },
        {
          title: '所属期刊',
          dataIndex: 'journalId',
          sorter: false,
          hideInSearch: false,
          hideInTable: true,
          valueType: 'hxJournalPicker',
        },
        {
          title: '所属期刊',
          width: 200,
          dataIndex: ["journal","journalNameCn"],
          sorter: false,
          hideInSearch: true,
          ellipsis: true,
        },
      ]}
      request={(p) => API.queryJournalPeriods(p)}
      entityKeys={{
        primaryKey: 'id',
        labelKey: 'periodName',
      }}
      {...props}
      className={classNames("hx-journal-period-table-select", props?.className)}
    />
  );
};

interface CompoundedComponent {
  Select: typeof HxJournalPeriodSelect;
  TableSelect: typeof HxJournalPeriodTableSelect;
}

const picker: CompoundedComponent = {
  Select: HxJournalPeriodSelect,
  TableSelect: HxJournalPeriodTableSelect,
};

export default picker;
